package org.tc.feign.platform;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.tc.feign.service.FeignManagersService;
import org.tc.platform.entity.Managers;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

//@RequestMapping("/Managers")
@RestController
@CrossOrigin(origins = {"*"}, methods = {RequestMethod.GET, RequestMethod.POST}, allowCredentials = "true")
public class FeignManagersController {
    @Autowired
    private FeignManagersService feignManagersService;

    @RequestMapping("/test2")
    @ResponseBody
    public String test2() {
        System.out.println("成功");
        return "成功";
    }

    //登陆成功存入姓名
    @RequestMapping("/Login")
    @ResponseBody
    public Managers Login(@RequestBody Managers managers, HttpServletRequest request) {
        System.out.println("登陆");
        Managers managers1 = feignManagersService.Login(managers);
        if (managers1 == null) {
            return null;
        } else {
            System.out.println(managers1.getNicknme());
            request.getSession().setAttribute("managers1", managers1);
            return managers1;
        }
    }

    //获取姓名
    @RequestMapping("/getname")
    @ResponseBody
    public Managers getname(HttpServletRequest request) {
        Managers managers = (Managers) request.getSession().getAttribute("managers1");
        System.out.println(request.getSession().getAttribute("managers1"));
        return managers;
    }

    /**
     * 管理员最高权限
     * 获取员工信息
     * @return
     */
    @RequestMapping(value = "/QueryAllManagers")
    @ResponseBody
    public List<Managers> QueryAllManagers()
    {
        List<Managers> list=feignManagersService.QueryAllManagers();
        return list;
    }


    @RequestMapping("/selectAll")
    @ResponseBody
    public List<Managers> QueryAll() {
        List list = feignManagersService.selectAll();
        return list;
    }


}
